import type { ProjectMemberRole } from './project'

export interface TeamMemberProjectInfo {
  id: string
  name: string
  status?: string | null
  priority?: string | null
  is_archived?: boolean
}

export interface TeamMemberUserInfo {
  id: string
  username?: string | null
  name?: string | null
  email?: string | null
  avatar?: string | null
  status?: string | null
  department?: string | null
  position?: string | null
}

export interface TeamMemberRecord {
  project: TeamMemberProjectInfo
  member: TeamMemberUserInfo
  roles: string[]
  role_names: string[]
  role_codes: string[]
  role?: ProjectMemberRole // 向后兼容，使用第一个角色代码
  permissions: string[]
  joined_at: string
}

export interface TeamMemberStatistics {
  total_members: number
  active_members: number
  inactive_members: number
  by_role: Record<string, number>
  by_project: Array<{
    project_id: string
    project_name?: string
    count: number
  }>
}

export interface TeamMemberPagination {
  total: number
  page: number
  size: number
  pages?: number
  has_prev?: boolean
  has_next?: boolean
}

export interface TeamMemberListResponse {
  items: TeamMemberRecord[]
  pagination: TeamMemberPagination
  statistics: TeamMemberStatistics
}

export interface TeamMemberQueryParams {
  project_id?: string
  role?: ProjectMemberRole | ''
  status?: string | ''
  keyword?: string
  page?: number
  size?: number
  sort_by?: 'joined_at' | 'project_name' | 'member_name' | 'member_status'
  sort_order?: 1 | -1
}

export interface CreateTeamMemberPayload {
  project_id: string
  user_id: string
  role: ProjectMemberRole
  permissions?: string[]
}

export interface UpdateTeamMemberPayload {
  role?: ProjectMemberRole // 向后兼容，单个角色代码
  roles?: string[] // 角色ID列表（优先使用）
  permissions?: string[]
}



